package com.Rendering;

import com.Gameplay.character.Role.parentRole;
import com.Rendering.Entity.PlayerRender;

import com.Rendering.UI.GameMainMenu.GameMainMenu;
import com.Rendering.StageScene.GameScene;

public class Renderer {
    public GameMainMenu gameMainMenu;
    public PlayerRender playerRender;
    private final GameScene gameScene;

    public Renderer(GameScene gameScene) {
        gameMainMenu = new GameMainMenu();
        playerRender = new PlayerRender();
        this.gameScene = gameScene;
    }

    public void GuiMainMenuRender() {
        gameMainMenu.loadMainMenu();
    }

    public void updateEntityRender(parentRole entity, parentRole entity2, float partialTicks) {
        gameScene.getEntityRenderGC().clearRect(0, 0, 2880, 900);
        playerRender.render(gameScene, entity, partialTicks);
        playerRender.render(gameScene, entity2, partialTicks);
    }


    public void updateCamara(parentRole p1, parentRole p2, float partialTicks) {
        double dx1 = p1.getPreX() + (p1.getCurrentX() - p1.getPreX()) * partialTicks;
        double dx2 = p2.getPreX() + (p2.getCurrentX() - p2.getPreX()) * partialTicks;
        double offset = -(dx1 + dx2) / 2 + 720.0D;
        if (offset <= 0 && offset >= -1440.0D) {
            gameScene.getLayout().getChildren().getFirst().setTranslateX(offset + 1440.0D);
            gameScene.getLayout().getChildren().get(1).setTranslateX(offset);
        }
    }

    public void draw(parentRole p1, parentRole p2) {
        gameScene.drawHUD(p1, p2);
    }
}
